//package com.yugao.fintech.antelope.auth.oauth2.service;
//
//import com.yugao.fintech.framework.core.http.HttpRequestServletManager;
//import com.yugao.fintech.framework.core.utils.IpUtils;
//import com.yugao.fintech.framework.core.utils.ServletUtils;
//import com.yugao.fintech.antelope.auth.model.LoginContextHolder;
//import com.yugao.fintech.antelope.base.model.module.auth.LoginUser;
//import com.yugao.fintech.antelope.base.security.utils.AddressUtils;
//import eu.bitwalker.useragentutils.UserAgent;
//import org.springframework.core.Ordered;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Objects;
//
///**
//
// */
//public interface MyUserDetailsService extends UserDetailsService, Ordered {
//
//	/**
//	 * 是否支持此客户端校验
//	 * @param clientId 目标客户端
//	 * @return true/false
//	 */
//	default boolean support(String clientId, String grantType) {
//		return true;
//	}
//
//	/**
//	 * 排序值 默认取最大的
//	 * @return 排序值
//	 */
//	default int getOrder() {
//		return 0;
//	}
//
//	/**
//	 * 构建 LoginContext
//	 */
//	default void fillLoginContext(LoginUser loginUser) {
//		if (Objects.isNull(loginUser)) {
//			throw new UsernameNotFoundException("");
//		}
//
//		setUserAgent(loginUser);
//		LoginContextHolder.get().setLoginUser(loginUser);
//	}
//
//	/**
//	 * 设置用户代理信息
//	 *
//	 * @param loginUser 登录信息
//	 */
//	default void setUserAgent(LoginUser loginUser) {
//		HttpServletRequest request = ServletUtils.getRequest().orElseThrow(() -> new RuntimeException("setUserAgent fail"));
//		UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
//		String ip = IpUtils.getRequestIp(new HttpRequestServletManager(request));
//		loginUser.setLoginIp(ip);
//		loginUser.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
//		loginUser.setBrowser(userAgent.getBrowser().getName());
//		loginUser.setOs(userAgent.getOperatingSystem().getName());
//	}
//
//	/**
//	 * 通过用户实体查询
//	 * @param authenticatedUser user
//	 */
//	default UserDetails loadUserByUser(AuthenticatedUser authenticatedUser) {
//		return this.loadUserByUsername(authenticatedUser.getUsername());
//	}
//}
